package com.woniu.zsd.platform.service.impl;

import com.woniu.zsd.platform.model.Suggestion;
import com.woniu.zsd.platform.dao.SuggestionMapper;
import com.woniu.zsd.platform.param.AddSuggestionParam;
import com.woniu.zsd.platform.param.ReplySuggestionParam;
import com.woniu.zsd.platform.service.SuggestionService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.time.LocalDateTime;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zhangtao
 * @since 2025年02月18日
 */
@Service
public class SuggestionServiceImpl extends ServiceImpl<SuggestionMapper, Suggestion> implements SuggestionService {
    @Resource
    private SuggestionMapper suggestionMapper;

    @Override
    public void addSuggestion(AddSuggestionParam param) throws Exception {
        Suggestion suggestion = new Suggestion();
        suggestion.setSuggestionContent(param.getSuggestionContent());
        suggestion.setStatus(0);
        suggestion.setCreatedAt(LocalDateTime.now());
        suggestion.setStationId(param.getStationId());
        suggestion.setStationName(param.getStationName());
        suggestion.setProposer(param.getProposer());
        suggestion.setProposerContact(param.getProposerContact());
        suggestionMapper.insert(suggestion);
    }

    @Override
    public void replySuggestion(ReplySuggestionParam param) throws Exception {
        Suggestion suggestion = suggestionMapper.selectById(param.getSuggestionId());
        if(suggestion==null){
            throw new Exception("回复的建议不存在");
        }
        suggestion.setReplyContent(param.getReplyContent());
        suggestion.setRepliedAt(LocalDateTime.now());
        suggestion.setStatus(1);
        suggestionMapper.updateById(suggestion);
    }
}
